package com.ophiux.FeverManagement.infratructure.repository;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ophiux.FeverManagement.domain.entity.DoctorInfo;
import com.ophiux.FeverManagement.domain.repository.IDoctorRepositories;
import com.ophiux.FeverManagement.infratructure.mapper.doctor.OphiuxDoctorInfoMapper;
import com.ophiux.utils.common.StringUtil;
import com.ophiux.utils.exception.OphiuxDaoException;
import com.ophiux.utils.exception.OphiuxRepositoryException;

import lombok.extern.slf4j.Slf4j;
@Repository
@Slf4j
public class DoctorRepositoriesImpl implements IDoctorRepositories{
	@Autowired
	OphiuxDoctorInfoMapper doctorInfoMapper;
	
	@Override
	public String save(DoctorInfo model) throws OphiuxRepositoryException {
		if(model == null) {
			return null;
		}
		String id = "";
		try {
			if(StringUtil.isEmpty(model.getUSER_ID())) {//新增
				id =  UUID.randomUUID().toString().replaceAll("-", "");
				model.setUSER_ID(id);
				model.setUSER_CODE(id);
				doctorInfoMapper.insert(model);
			}else {
				id = model.getUSER_ID();
				doctorInfoMapper.update(model);
			}
		}catch (Exception e) {
			e.printStackTrace();
			log.info("DoctorRepositoriesImpl=>save(),数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException("DoctorRepositoriesImpl=>save(),数据库执行异常");
		}
		
		return id;
		
	}

	@Override
	public void delete(Object uniqueId) throws OphiuxRepositoryException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public DoctorInfo selectOneByKey(Object uniqueId) throws OphiuxRepositoryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DoctorInfo selectOne(Map map) throws OphiuxRepositoryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<DoctorInfo> selectAll(Map map) throws OphiuxRepositoryException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DoctorInfo getDoctorByOtherId(String otherId)  throws OphiuxRepositoryException{
		DoctorInfo doctor = null;
		if(StringUtil.isEmpty(otherId)) {
			return doctor;
		}
		try {
			doctor = doctorInfoMapper.getDoctorByOtherId(otherId);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("DoctorRepositoriesImpl=>getDoctorByOtherId(),数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException("DoctorRepositoriesImpl=>getDoctorByOtherId(),数据库执行异常");
		}
		return doctor;
	}

	@Override
	public DoctorInfo getDoctorByPhone(String Phone)  throws OphiuxRepositoryException{
		DoctorInfo doctor = null;
		if(StringUtil.isEmpty(Phone)) {
			return doctor;
		}
		try {
			doctor = doctorInfoMapper.getDoctorByPhone(Phone);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("DoctorRepositoriesImpl=>getDoctorByPhone(),数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException("DoctorRepositoriesImpl=>getDoctorByPhone(),数据库执行异常");
		}
		return doctor;
	}

}
